<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Supply_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 根据分页信息返回进货单信息
	 */
	public function find_all_supplys($per_page,$offset,$name){
		$this->db->like('name', $name);	
		$this->db->limit($per_page, $offset);
		$this->db->order_by("id", "desc");
		$query = $this->db->get('s_supply');
		return $query->result_array();
	}
	/*
	 * 返回进货单总数
	 */
	public function count_supplys($name){
		$this->db->like('name', $name);	
		$query = $this->db->get('s_supply');
		return $query->num_rows();
	}
	/*
	 * 根据ID返回进货单信息
	 */
	public function load($id){
		$query = $this->db->get_where('s_supply',array('id' => $id));
		if ($row = $query->row_array()){
			return $row;
		}
		return array();
	}
	/*
	 * 添加进货单信息
	 */
	public function create($supply){
		$this->db->insert('s_supply', $supply);
		return $this->db->insert_id();
	}
	/*
	 * 更新进货单信息
	 */
	public function update($id,$supply){
		$this->db->where('id', $id);
		$this->db->update('s_supply', $supply);
		return $this->db->affected_rows()>0;
	}
	/*
	 * 删除进货单信息
	 */
	public function delete($id){
		$this->db->where('id', $id);
		$this->db->delete('s_supply');
		return $this->db->affected_rows()>0;
	}
	/*
	 * 根据日期返回进货单信息
	 */
	public function find_export_supplys($supply_time){
		$this->db->where('supply_time', $supply_time);
		$query = $this->db->get('s_supply');
		return $query->result_array();
	}
}